#!/usr/bin/env python
#-*- encoding: utf-8 -*-

def s(n):
    if n % 2 == 0:
        return n / 2
    else:
        return 3 * n + 1

def chainLength(n):
    startN = n
    c = 1
    
    while n != 1:
        if n in memory:
            c += memory[n]
            break
        n = s(n)
        c += 1
    memory[startN] = c
    return c

memory = {}
max = 0
a = 0
for i in xrange(1,1000000):
#    if i % 1000 == 0: print i
    c = chainLength(i)
    if c > max:
        max = c
        a = i

print a
